﻿// ConverterSurrogate.cs
//
// Copyright 2008 by Burt Harris
// Licensed under the Microsoft Public License (Ms-PL)
// See: http://www.codeplex.com/yaml/license
//
namespace YaTools.Yaml.Serialization
{
    using System;
    using System.Diagnostics;
    using System.Runtime.Serialization;
    using System.Security.Permissions;

    [DebuggerDisplay("ConvertSurrogate")]
    public sealed class ConvertSurrogate : YamlSurrogate 
    {
        // private sngleton constructor
        private ConvertSurrogate() { }

        static Uri s_baseUri = new Uri("tag:yatools.net,2009:convert,");

        protected override Uri BaseUri
        {
            get { return s_baseUri; }
        }

        [SecurityPermission(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.SerializationFormatter)]
        public override void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
        {
            var writer = context.YamlWriter();
            writer.WriteItem(Convert.ToString(obj), null);
        }

        [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
        public override object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
        {
            throw new NotImplementedException();
        }


        public static ConvertSurrogate Instance { get { return _instance; } }
        private static ConvertSurrogate _instance = new ConvertSurrogate();
    }
}
